package com.ruoyi.exam.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.exam.vo.ExamQuestionImportLogVo;
import com.ruoyi.exam.service.IExamQuestionImportLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 题目导入记录Controller
 *
 * @author Tellsea
 * @date 2025-05-30
 */
@Api(tags = "题目导入记录Controller")
@RestController
@RequestMapping("/exam/questionImportLog")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ExamQuestionImportLogController extends BaseController {

    private final IExamQuestionImportLogService examQuestionImportLogService;

    @ApiOperation("查询题目导入记录列表")
    @PreAuthorize("@ss.hasPermi('exam:questionImportLog:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamQuestionImportLogVo> list(ExamQuestionImportLogVo entity) {
        return examQuestionImportLogService.queryList(entity);
    }

    @ApiOperation("查询题目导入记录所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ExamQuestionImportLogVo entity) {
        return AjaxResult.success("查询成功", examQuestionImportLogService.queryAll(entity));
    }

    @ApiOperation("导出题目导入记录列表")
    @PreAuthorize("@ss.hasPermi('exam:questionImportLog:export')")
    @Log(title = "题目导入记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQuestionImportLogVo entity) {
        List<ExamQuestionImportLogVo> list = examQuestionImportLogService.queryAll(entity);
        ExcelUtil<ExamQuestionImportLogVo> util = new ExcelUtil<>(ExamQuestionImportLogVo.class);
        util.exportExcel(response, list, "题目导入记录数据");
    }

    @ApiOperation("获取题目导入记录详细信息")
    @PreAuthorize("@ss.hasPermi('exam:questionImportLog:query')")
    @GetMapping(value = "/getInfo/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId) {
        return AjaxResult.success("查询成功", examQuestionImportLogService.queryById(logId));
    }

    @ApiOperation("新增题目导入记录")
    @PreAuthorize("@ss.hasPermi('exam:questionImportLog:add')")
    @Log(title = "题目导入记录", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ExamQuestionImportLogVo entity) {
        return toAjax(examQuestionImportLogService.save(entity));
    }

    @ApiOperation("修改题目导入记录")
    @PreAuthorize("@ss.hasPermi('exam:questionImportLog:edit')")
    @Log(title = "题目导入记录", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ExamQuestionImportLogVo entity) {
        return toAjax(examQuestionImportLogService.updateById(entity));
    }

    @ApiOperation("删除题目导入记录")
    @PreAuthorize("@ss.hasPermi('exam:questionImportLog:remove')")
    @Log(title = "题目导入记录", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds) {
        return toAjax(examQuestionImportLogService.removeByIds(Arrays.asList(logIds)) ? 1 : 0);
    }
}
